object EitherTest {
  /**
    * 相当于Parse 方法
    */
  def main(args: Array[String]): Unit = {

    def process(b: Double): Double = {
      val a = 10.0
      a / b
    }

    /**
      * Either => Left Or Right
      * option => Some None
      *
      * @param f
      * @param b
      * @return
      */
    def safe(f: Double => Double, b: Double): Either[Double, (Double, Exception)] = {
      try {
        val result = f(b)
        Left(result)
      } catch {
        case e: Exception => Right(b, e)
      }
    }

    val result = safe(process, 0)
    result match {
      case Left(r) => println(r)
      case Right((b, e)) => println(b, e)
    }
  }
}